#pragma once

#include <string>
#include "NetworkModule.h"
#include "UserManager.h"
#include "MessageHandler.h"

class ChatServer
{
public:
    ChatServer(int port);
    bool start();
    void stop();

private:
    NetworkModule networkModule;
    UserManager userManager;

    void handleClientMessage(int clientSocket, const std::string &message);
    void handleLogin(int clientSocket, const MessageHandler::Message &msg);
    void handleLogout(int clientSocket, const MessageHandler::Message &msg);
    void handlePrivateMessage(int clientSocket, const MessageHandler::Message &msg);
    void handleBroadcastMessage(int clientSocket, const MessageHandler::Message &msg);
    void handleClientDisconnect(int clientSocket);
    void broadcastMessage(const std::string &sender, const std::string &content);
    void sendError(int clientSocket, const std::string &errorMsg);
};